﻿#pragma once
#include<sstream>
#include<cstring>
#include<thread>
#include <stdarg.h>
#include<unordered_map>
namespace wjc {

    class Utils {
    public:
        enum FileType {
            IMAGE=0,
            VIDEO,
            PDF,
            TXT,
            HTML,
            XML,
            JSON,
            WORD,
            OTHER,
        };

        static std::string hostname();

        static pid_t pid();

        static std::string getTid() {
            std::ostringstream oss;
            oss << std::this_thread::get_id();
            return oss.str();
        }

        static std::string getTime()
        {
            time_t timep;
            time(&timep);
            char tmp[64];
            strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&timep));
            return tmp;
        }

        static void memZero(void* p, size_t n)
        {
            memset(p, 0, n);
        }

        //返回拷贝的大小,-1表示失败
        static size_t joinPath(char* dest, size_t size, std::initializer_list<const char*> il);

        //解析key=value&&key=value
        static void parseKeyValue(const char* text, size_t size, std::unordered_map<std::string, std::string>& map);

        static std::string getContentTypeByFileName(const char* filename, size_t size);

        static FileType getFileType(const char* filename, size_t size);

        static std::string getImageHTML(const char* url, const char* filename);

        static std::string getVideoHTML(const char* url, const char* filename);

        //创建目录
        static bool CreateDir(const char* sPathName);
    };
}
